﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Gnosis.Alexandria.Model
{
    public abstract class NamedBase
        : IdentifiableBase, INamed
    {
        private string _name = string.Empty;

        protected override void InitializeField(string fieldName, object value)
        {
            if (fieldName == "Name")
            {
                var name = (string)value ?? string.Empty;
                _name = name;
                NameSet(name);
            }
            else base.InitializeField(fieldName, value);
        }

        protected virtual void NameSet(string name)
        {
        }

        #region INamed Members

        public string Name
        {
            get { return _name; }
            set
            {
                if (_name != value)
                {
                    _name = value;
                    NameSet(value);
                    AddChange("Name", value);
                }
            }
        }

        #endregion

        public override string ToString()
        {
            return Name;
        }
    }
}
